package models.order;

import javax.persistence.*;

import java.sql.*;
import java.sql.Blob;

import javax.sql.*;

import models.seller.amazon.AmazonSellerAccount;
import models.seller.ebay.EbaySellerAccount;
import models.user.Customer;
import controllers.Application;

import java.math.*;
import java.util.*;
import java.util.Date;

import play.db.jpa.Model;
import play.cache.Cache;
import play.db.jpa.*;
import play.mvc.Scope;

/**
 * 订单表：通常由客户 ebay , amazon订单转换而成; 也可以理解为本公司的运单信息
 * 
 * 表名:o_order 是因为order 是mysql 保留词.无奈
 * @author yechao
 * @date 2013年11月2日
 */
@Entity
@Table(name = "o_order")
public class Order extends Model {
	/**
	 * 客户Id customer表的id
	 */
	@Column(name = "customer_id")
	public Long customerId;
	/**
	 * 客户帐号
	 */
	@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "customer_id", insertable = false, updatable = false)
	public Customer customer;
	/**
	 * 订单状态
	 */
	@Column(name = "status")
	public Integer status;
	/**
	 * 订单创建时间
	 */
	@Column(name = "created_time")
	public Date createdTime;

	/**
	 * ebay amazon 平台订单编号
	 */
	@Column(name = "sales_order_no")
	public String salesOrderNo;

	/**
	 * 订单物品明细
	 */
	@OneToMany(mappedBy = "orderId", fetch = FetchType.LAZY)
	public List<OrderItem> orderItems;

	/**
	 * 订单报关明细
	 */
	@OneToMany(mappedBy = "orderId", fetch = FetchType.LAZY)
	public List<OrderCustoms> orderCustoms;

	/**
	 * 收件人id
	 */
	@Column(name = "receiver_id")
	public Long receiverId;

	/**
	 * 收件人
	 */
	@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "receiver_id", insertable = false, updatable = false)
	public OrderReceiver receiver;

	/**
	 * 发件人id
	 */
	@Column(name = "sender_id")
	public Long senderId;

	/**
	 * 发件人
	 */
	@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "sender_id", insertable = false, updatable = false)
	public OrderSender sender;

	/**
	 * amazon卖家帐号 如果订单来自amazon等平台,此字段才有值
	 */
	@Column(name = "amazon_seller_account_id")
	public Long amazonSellerAccountId;

	/**
	 * 客户amazon帐号 可选
	 */
	@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "amazon_seller_account_id", insertable = false, updatable = false)
	public AmazonSellerAccount amazonSellerAccount;

	/**
	 * ebay 卖家帐号id
	 */
	@Column(name = "ebay_seller_account_id")
	public Long ebaySellerAccountId;

	/**
	 * 客户ebay帐号 可选
	 */
	@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "ebay_seller_account_id", insertable = false, updatable = false)
	public EbaySellerAccount ebaySellerAccount;

	/**
	 * ebay amazon 的买家Id
	 */
	@Column(name = "buyer_id")
	public String buyerId;

	/**
	 * 订单在ebay,amazon 平台的状态 已付款,已标记发货 等
	 */
	@Column(name = "online_status")
	public Integer onlineStatus;

	/**
	 * 客户参考号
	 */
	@Column(name = "customer_reference_number")
	public String customerReferenceNumber;

}
